﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;

public partial class Entity : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
           Response.ContentType = "text/plain";
    }

    public string TableName
    {
        get
        {
            return Request["TableName"];
        }
    }

    public string TableName_Emoney
    {
        get
        {
            var tbName = TableName.ToLower();
            if (tbName.EndsWith("_msn"))
            {
                return TableName.Substring(0, TableName.Length - 4);
            }
            return TableName;
        }
    }

    public List<Code.DAL.Table> CurrentDables
    {
        get
        {
            return (List<Code.DAL.Table>)Session["Tables"];
        }
    }

    public Code.DAL.Table CurrentTable
    {
        get
        {
            return CurrentDables.Find(x => x.Name == TableName);
        }
    }

    public string TableDesc
    {
        get
        {
            return CurrentTable.Desc;
        }
    }

    public string Columns
    {
        get
        {
            var cols = CurrentTable.Columns;
            StringBuilder sb = new StringBuilder();
            string kg = "        ";
            for (int i = 0; i < cols.Count; i++)
            {
                var c = cols[i];
                var name=c.Name;
                name=name.Substring(0,1).ToUpper()+name.Substring(1);
                sb.AppendLine(kg+"/// <summary>");
                sb.AppendLine(kg+"///"+c.Desc);
                sb.AppendLine(kg+"/// </summary>");
                sb.AppendLine(kg+"public "+ColType.GetColType(c)+" " + name);
                sb.AppendLine(kg+"{");
                sb.AppendLine(kg + "   get;");
                sb.AppendLine(kg + "   set;");
                sb.AppendLine(kg+"}");
                sb.AppendLine();
            }
            return sb.ToString();
        }
    }

}